import os
from pathlib import Path

# 需要清理的根目录
base_dir = r"G:\extracted_packages"

# 虚拟js文件的命名特征
virtual_js_prefix = "_virtual_package_script"

# 遍历malicious和benign子目录
for sub in ["malicious", "benign"]:
    sub_dir = Path(base_dir) / sub
    if not sub_dir.exists():
        continue
    for pkg in sub_dir.iterdir():
        if pkg.is_dir():
            for f in pkg.glob(f"{virtual_js_prefix}*.js"):
                try:
                    f.unlink()
                    print(f"已删除: {f}")
                except Exception as e:
                    print(f"删除失败: {f}，原因: {e}")